﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Generic;

namespace VirtualTournaments.Frontend.MenuControls.GenericControls
{
    using Team = Services.Tournaments.Team;
    using TeamsService = Services.Tournaments.TeamsService;

    public partial class TournamentInfo : System.Web.UI.UserControl
    {
        public EventHandler GoToTeamInfo;

        public ListBox TeamsListBox 
        {
            get 
            {
                return teamsListBox;
            }
            set 
            {
                teamsListBox = value;
            }
        }

        public string TournamentName
        {
            get 
            {
                return TournamentNameLabel.Text;
            }
            set 
            {
                TournamentNameLabel.Text = value;
            }
        }

        public string TournamentType 
        {
            get 
            {
                return TournamentTypeLabel.Text;
            }
            
            set 
            {
                TournamentTypeLabel.Text = value;
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (!TournamentName.Equals(string.Empty))
            {
                this.teamsListBox.Items.Clear();
                Team[] teams = TeamsService.GetTeamsByTournamentName(TournamentName);
                foreach(Services.Tournaments.Team team in teams)
                {
                    this.teamsListBox.Items.Add(team.Name);
                }
            }
        }

        protected void ButtonViewTeamInfo_OnClick(object sender, EventArgs e) 
        {
                GoToTeamInfo(this, new VirtualTournamentsFrontendEvent { TeamName = teamsListBox.SelectedValue });
        }

    }
}